home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Learn C++ (CodeWarrior)
/
Chap 06.04 - whatAmI
/
whatAmI.cp
< prev
next >
Wrap
Text File
|
1995-10-20
|
930b
|
70 lines
#include <iostream.h>
//--------------------------------------- Shape
class Shape
{
// Data members...
// Member functions...
public:
virtual void WhatAmI();
};
void Shape::WhatAmI()
{
cout << "I don't know what kind of shape I am!\n";
}
//--------------------------------------- Shape:Rectangle
class Rectangle : public Shape
{
// Data members...
// Member functions...
public:
void WhatAmI();
};
void Rectangle::WhatAmI()
{
cout << "I'm a rectangle!\n";
}
//--------------------------------------- Shape:Triangle
class Triangle : public Shape
{
// Data members...
// Member functions...
public:
void WhatAmI();
};
void Triangle::WhatAmI()
{
cout << "I'm a triangle!\n";
}
//--------------------------------------- main()
int main()
{
Shape *s1, *s2, *s3;
s1 = new Rectangle;
s2 = new Triangle;
s3 = new Shape;
s1->WhatAmI();
s2->WhatAmI();
s3->WhatAmI();
return 0;
}